<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<% 
 /**
  功能名称:学生分班
  创建时间:2010-7-6
  创建人:
**/
%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>学生分班</title>
	<link href="<%=path%>/css/index_css.css" rel="stylesheet" type="text/css" />
	<style type="text/css">
		.new_class_first,.new_class{margin:0 1px;padding-left:4px;float:left;display:block;white-space:nowrap;}
		.new_class{border-left:#000 1px solid;}
	</style>
	<script language="javascript" src="<%=path %>/js/syAjax.js"></script>
	<script language="javascript" src="<c:url value='/js/json2.js'/>"></script>
	<script src="<%=path%>/js/resizeIframe.js" type="text/javascript"></script>
	<script type="text/javascript">
		window.onload = function(){
			parent.location.hash="top";
	      	
	      	resizeIframe();
	    }
		function showOrHidden(gradeId){			
			if(document.getElementById('div'+gradeId).style.display=='none'){
				document.getElementById('div'+gradeId).style.display='';
			}else{
				document.getElementById('div'+gradeId).style.display='none';
			}
			
	      	resizeIframe();
	        
	          
	        			
		}
		
		function showStuByClassId(classId,className){
			document.getElementById('classId').value=classId;
			document.getElementById('curClassName').innerHTML=className;
			//发送ajax请求，根据班级id，获取该班级下的学生
			syAjax.request("post","<%=path %>/getStuListByClassIdGradeAndClassAction.action","classes.classId="+classId,{success:initSuccessResult,fail:onFail,type:'plain'});						
		}		
		function initSuccessResult(response){
			//先将两个全选按钮设为未选中
			document.getElementById('chkHasClassStu').checked=false;
			document.getElementById('chkNoClassStu').checked=false;
			var sexMap={};
			sexMap['']='';
			<c:forEach var="s" items="${sexMap}">sexMap['${s.key}']='${s.value}';</c:forEach>//添加 @date:2011-7-6 13:25:00
			var data = JSON.parse(response);
			var showStr="<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#DCDCDC\">";
			if(data!=null){				
				if(data.length>0){
					for(var i=0;i<data.length;i++){
					var sexName="";
					if(sexMap[data[i].sex]!=undefined){
						sexName = sexMap[data[i].sex];
					}
showStr+="<tr><td width=\"36\" height=\"25\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\"><input type=\"checkbox\" name=\"classStu\" value=\""+data[i].userId+"\" /></td><td width=\"290\" bgcolor=\"#FFFFFF\">&nbsp;"+data[i].account+"："+data[i].name+"</td><td width=\"117\" align=\"center\" bgcolor=\"#FFFFFF\">"+sexName+"</td></tr>";// @date:2011-7-6 13:24:17			
					}
				}else{
					showStr+="<tr><td colspan=\"3\" height=\"25\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\">暂无数据</td></tr>";
				}
			}
			showStr+="</table>";
			document.getElementById('classStuList').innerHTML=showStr;
			
	      	resizeIframe();
	        
	          
	        
		}
		
		function onFail(){
			alert("网络繁忙，请稍后再试");
		}
		
		
		function doStuAdd(){
			var classId = document.getElementById('classId').value;
			var uuidList="";
			if(classId==""){
				alert("请选择班级");
			}else{
				var uuidArr = document.getElementsByName("nostu");
				if(uuidArr!=null && uuidArr!=""){
					for(var i=0;i<uuidArr.length;i++){
						if(uuidArr[i].checked==true){
							uuidList+=uuidArr[i].value+",";
						}
					}
					//发送ajax请求，根据班级id，获取该班级下的学生
					syAjax.request("post","<%=path %>/doStuToClassGradeAndClassAction.action","year=${applicationScope.currentYear}&classes.classId="+classId+"&uuidList="+uuidList,{success:initSuccessResult2,fail:onFail,type:'plain'});					
				}else{
					alert("没有需要分班的学生");
				}
			}
			
		}
		
		function initSuccessResult2(response){
			  if(response=="超出招生规模限制，无法分班！")
			  {
			     alert(response);
			  }else
			  {
			  //先将两个全选按钮设为未选中
			  document.getElementById('chkHasClassStu').checked=false;
			  document.getElementById('chkNoClassStu').checked=false;
			  var data = JSON.parse(response);
			  var sexMap={};
			  sexMap['']='';
			<c:forEach var="s" items="${sexMap}">sexMap['${s.key}']='${s.value}';</c:forEach>//添加 @date:2011-7-6 13:25:00
			   //1.获取班级的数据
				var showStr="<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#DCDCDC\">";
				if(data!=null){				
					if(data[0].length>0){					 
						for(var i=0;i<data[0].length;i++){
						var sexName="";
						if(sexMap[data[0][i].sex]!=undefined){
							sexName = sexMap[data[0][i].sex];
						}
							showStr+="<tr><td width=\"36\" height=\"25\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\"><input type=\"checkbox\" name=\"classStu\" value=\""+data[0][i].userId+"\" /></td><td width=\"290\" bgcolor=\"#FFFFFF\">&nbsp;"+data[0][i].account+"："+data[0][i].name+"</td><td width=\"117\" align=\"center\" bgcolor=\"#FFFFFF\">"+sexName+"</td></tr>";//	@date:2011-7-6 13:23:57
				
						}
					}else{
						showStr+="<tr><td colspan=\"3\" height=\"25\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\">暂无数据</td></tr>";
					}
				}
				showStr+="</table>";
				document.getElementById('classStuList').innerHTML=showStr;
				//2.获取未分班的数据
				var showStr2="<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#DCDCDC\">";
				if(data!=null){				
					if(data[1].length>0){
					 
						for(var i=0;i<data[1].length;i++){
							var sexName="";
							if(sexMap[data[1][i].sex]!=undefined){
								sexName = sexMap[data[1][i].sex];
							}
							showStr2+="<tr><td width=\"8%\" height=\"25\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\"><input type=\"checkbox\" name=\"nostu\" value=\""+data[1][i].userId+"\" /></td><td width=\"68%\" bgcolor=\"#FFFFFF\">&nbsp;"+data[1][i].account+"："+data[1][i].name+"</td><td width=\"24%\" align=\"center\" bgcolor=\"#FFFFFF\">"+sexName+"</td></tr>";
						}
					}else{
						showStr2+="<tr><td colspan=\"3\" height=\"25\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\">暂无数据</td></tr>";
					}
				}
				showStr2+="</table>";
				document.getElementById('noClassStuList').innerHTML=showStr2;
				
	      	resizeIframe();
	        
	          
	        
			  }
				
		}
		
		
		function doDelete(){
			var classId = document.getElementById('classId').value;
			var uuidList="";
			if(classId==""){
				alert("请选择班级");
			}else{
				var uuidList="";
				var uuidArr = document.getElementsByName("classStu");
				if(uuidArr!=null && uuidArr!=""){
					for(var i=0;i<uuidArr.length;i++){
						if(uuidArr[i].checked==true){
							uuidList+=uuidArr[i].value+",";
						}
					}
					//发送ajax请求，根据班级id，获取该班级下的学生
					syAjax.request("post","<%=path %>/deleteStuFromOneClassGradeAndClassAction.action","year=${applicationScope.currentYear}&classes.classId="+classId+"&uuidList="+uuidList,{success:initSuccessResult2,fail:onFail,type:'plain'});					
				}else{
					alert("请选择要删除的学生");
				}
		    }
		    
		}
		
		function chkAll(parId,sonName){
			var chkArr = document.getElementsByName(sonName);
			if(chkArr!=null && chkArr.length>0){
				for(var i =0; i<chkArr.length;i++){
					if(chkArr[i].type=="checkbox"){
						chkArr[i].checked = document.getElementById(parId).checked;
					}
				}
			}
		}
		function searchStudent(){
			var account=document.getElementById("account").value;
			syAjax.request("post","<%=path %>/searchNoClassStudentsGradeAndClassAction.action","year=${applicationScope.currentYear}&account="+account,
			{success:function(response){
					  //先将两个全选按钮设为未选中
					  //document.getElementById('chkHasClassStu').checked=false;
					  document.getElementById('chkNoClassStu').checked=false;
					  var data = JSON.parse(response);
					  var sexMap={};
					  sexMap['']='';
					<c:forEach var="s" items="${sexMap}">sexMap['${s.key}']='${s.value}';</c:forEach>//添加 @date:2011-7-6 13:25:00
					   
						//2.获取未分班的数据
						var showStr2="<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#DCDCDC\">";
						if(data!=null&&data.length>0){
							for(var i=0 in data){
								var sexName="";
								if(sexMap[data[i].sex]!=undefined){
									sexName = sexMap[data[i].sex];
								}
								showStr2+="<tr><td width=\"8%\" height=\"25\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\"><input type=\"checkbox\" name=\"nostu\" value=\""+data[i].userId+"\" /></td><td width=\"68%\" bgcolor=\"#FFFFFF\">&nbsp;"+data[i].account+"："+data[i].name+"</td><td width=\"24%\" align=\"center\" bgcolor=\"#FFFFFF\">"+sexName+"</td></tr>";				
							}
						}else{
							showStr2+="<tr><td colspan=\"3\" height=\"25\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\">暂无数据</td></tr>";
						}
						showStr2+="</table>";
						document.getElementById('noClassStuList').innerHTML=showStr2;
						
			      	resizeIframe();
			        
			          
			        
						
				},fail:onFail,type:'plain'
			});
		}	
		
		function excelImport(){
		document.excelForm.submit();
		<%--window.location.href ="<%=path%>/student/batch/toImportExcle()?from=${param.from}&orgId=${cla.classId}";	--%>
		}
	</script>

  </head>
  
  <body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2" align="left" class="f_5">学生分班</td>
  </tr>
  
  <tr>
    <td height="1" colspan="2" bgcolor="#9DD12E"></td>
  </tr>
  <tr>
  	  <td align="right" valign="top" bgcolor="#FFFFFF"><img src="<%=path %>/images/disk_icon_excel.gif" width="16" /><a href="javascript:excelImport();">从excel导入班级信息</a></td> 	
  </tr>
  <tr>
    <td colspan="2" align="left" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="left" valign="bottom" background="<%=path %>/images/sywesp_24.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="90" align="left"><table width="90" border="0" cellspacing="0" cellpadding="0">        
              <tr>
                <td width="1" align="left" valign="bottom" bgcolor="#CBCBCB"></td>
                <td align="left" background="<%=path %>/images/sywesp_25.gif" class="f_9">学生分班</td>
                <td width="1" height="31" align="right" valign="bottom" bgcolor="#CBCBCB"></td>
              </tr>
            </table></td>
            <td align="left" style="padding:0 4px;"><!-- 添加2011-10-17 13:51:31 -->
            &nbsp;
            </td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td align="left" valign="top" class="tb_8 border_2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="50%" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="321" height="25" colspan="3" align="center"><span class="f_9">已分班学生名单</span>[当前班级:<span id="curClassName"></span>]</td>
                </tr>              
            </table>
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="25" class="tb_12 f_2">&nbsp;&nbsp;&nbsp;班级名称</td>
                  <td class="tb_12">&nbsp;</td>
                  <td width="36" align="center" class="tb_12"><input id="chkHasClassStu" onclick="chkAll('chkHasClassStu','classStu');" type="checkbox" name="checkbox1122" value="checkbox" /></td>
                  <td width="290" align="left" class="tb_12 f_2">&nbsp;帐号：姓名</td>
                  <td width="117" align="center" class="tb_12 f_2">性别</td>
                </tr>
                <tr>
                  <td height="1" colspan="5"></td>
                  </tr>
                <tr>
                  <td width="162" align="left" valign="top" class="tb_13 border_3">
                  
                  <!-- 遍历年级开始 -->
                  <c:if test="${requestScope.GRADELIST!=null}">
                  <c:forEach var="g" items="${requestScope.GRADELIST}">
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="15%" height="25" align="center"><img src="<%=path %>/images/bk_10.gif" width="13" height="13" /></td>
                      <td width="85%" align="left" nowrap="nowrap"><a href="javascript:showOrHidden('${g.gradeId}');" class="style3">${g.name }</a></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td align="left">
                      
                      <div id="div${g.gradeId }" style="display:none;">
                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <!-- 遍历班级开始 -->
                          <c:if test="${not empty requestScope.CLASSMAP[g.gradeId]}">
                          <c:forEach var="class" items="${requestScope.CLASSMAP[g.gradeId]}">
                          <tr>
                            <td width="14%" align="center"><img src="<%=path %>/images/bk_14.gif" width="6" height="5" /></td>
                            <td width="86%" height="25" nowrap="nowrap"><a href="javascript:showStuByClassId('${class.classId}','${class.name}');">${class.name }</a></td>
                          </tr>
                          </c:forEach>
                          </c:if>
                          <c:if test="${empty requestScope.CLASSMAP[g.gradeId]}">
                          	<tr>
                          	<td width="14%" align="center"><img src="<%=path %>/images/bk_14.gif" width="6" height="5" /></td>                   
                            <td width="86%" height="25" nowrap="nowrap">暂无班级</td>
                          </tr>
                          </c:if>
                          <!-- 遍历班级结束 -->
                      </table>
                      </div>
                      
                      </td>
                    </tr>
                  </table>
                  </c:forEach>
                  </c:if>
                  <c:if test="${requestScope.GRADELIST==null}">
                  	暂未设置年级班级
                  </c:if>
                  <!-- 遍历年级结束 -->
                   
                    </td>
                  <td width="6">&nbsp;</td>
                  <td colspan="3" align="left" valign="top">
                  <div id="classStuList" style="height: 300px;overflow-y: auto;overflow-x:auto;">
	                  <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#DCDCDC">	                    
	                    <tr>
	                      <td colspan="3" height="25" align="center" valign="middle" bgcolor="#FFFFFF">暂无数据</td>
	                    </tr>                                                            
	                  </table>
                  </div>
                  </td>
                  </tr>
              </table></td>
            <td align="center" valign="middle"><table width="100" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="50" align="center"><input type="button" onclick="doStuAdd();" name="Submit2" value="&lt;&lt;添加" /></td>
              </tr>
              <tr>
                <td height="50" align="center"><input type="button" onclick="doDelete();" name="Submit22" value="删除&gt;&gt;" /></td>
              </tr>
            </table></td>
            <td width="40%" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="321" height="25" colspan="3" align="center"><span class="f_9">待分班学生名单</span></td>
              </tr>
            </table>
            <div>
            	特征帐号：<input name="account" id="account" maxlength="20" style="width:100px;"/><button onclick="searchStudent();" type="button">搜索</button>
            </div>
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="8%" height="25" align="center" class="tb_12"><input id="chkNoClassStu" onclick="chkAll('chkNoClassStu','nostu');" type="checkbox" name="checkbox11232" value="checkbox" /></td>
                  <td width="68%" class="tb_12 f_2">&nbsp;帐号：姓名</td>
                  <td width="24%" align="center" class="tb_12 f_2">性别</td>
                </tr>
                <tr>
                  <td height="1"></td>
                  <td></td>
                  <td></td>
                </tr>
                <tr>                	
                  <td colspan="3" align="left" valign="top">
                  <input type="hidden" id="classId" value=""/>
                  <div id="noClassStuList" style="height: 300px;overflow-y: auto;overflow-x:auto;">
                  <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#DCDCDC">
                    <c:forEach var="stu" items="${requestScope.STULIST}">
                    <tr>
                      <td width="8%" height="25" align="center" valign="middle" bgcolor="#FFFFFF"><input type="checkbox" name="nostu" value="${stu.userId}" /></td>
                      <td width="68%" bgcolor="#FFFFFF">&nbsp;${stu.account }：${stu.name }</td>
                      <td width="24%" align="center" bgcolor="#FFFFFF">${sexMap[stu.sex] }</td>
                    </tr>
                    </c:forEach>                 
                  </table>
                  </div>
                  </td>
                  </tr>
              </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      
    </table></td>
  </tr>
</table>

<form name="excelForm" action="<%=path %>/toImportExcleGradeAndClassAction.action" method="post">
<input type="hidden" id="excelbackURL" name="backURL" value="<%=path %>/toStuToClassGradeAndClassAction.action?year=${applicationScope.currentYear}">
</form>
</body>
</html>
